#{extends 'site.html' /} 
#{set title:'Search question' /}

<h2>Search Question</h2>

<ul class="addingItem">
	<li>
		<a href="@{Questions.create()}">Or add a new one</a>
	</li>
</ul>

#{form @Questions.search()} 

	#{ifErrors}
		<p class="error">All fields are required!</p>
	#{/ifErrors}
	
	<table class="table-filter">
		<tbody>
			<tr>
				<td align="right"><label for="questionTitle">Title: </label></td>
				<td><input type="text" name="questionTitle" id="questionTitle" value="${questionTitle}" /></td>
				<td align="right"><label for="groupType">Type: </label></td>
				<td>#{select 'groupType', items:models.GroupType.findAll(true), valueProperty:'id', value:groupType, labelProperty:'name', id:'group_types' /}</td>
			</tr>
			<tr>
				<td align="right"><label for="difficulty">Min difficulty: </label></td>
				<td>#{difficulty star:difficulty/}</td>
				<td align="right"><label for="second">Min time: </label></td>
				<td><input type="text" name="second" id="second" value="${second}" /><span class="info"> (seconds)</span></td>
			</tr>
		</tbody>
	</table>
           
     <p>
        <input type="submit" value="Search" />
     </p>
  
  #{/form} 
	
<div>
	<table>
		<thead>
			<tr>
				<th>Title</th>
                <th>Difficulty</th>
                <th>Time</th>
                <th>Type</th>
			</tr>
		</thead>
		<tbody>
		  #{list items:questions, as:'question'}
			<tr>
				<td>#{a @Questions.view(question.id)}${question.title}#{/a}</td>
	         <td>#{difficulty star:question.difficulty, discriminator:question.id, readonly:true, split:false/}</td>
            <td>${question.second}</td>
            <td>${question.groupType.name}</td>
			</tr>
			#{/list}
			#{else}
			<tr>
			   <td colspan="4" class="no-response">No question. Change filter values.</td>
			</tr>
			#{/else}
		</tbody>
	</table>

</div>








